package cn.edu.csust.coursecard.controller;

import cn.edu.csust.coursecard.annotation.RequiredAdmin;
import cn.edu.csust.coursecard.dao.entity.Association;
import cn.edu.csust.coursecard.dao.entity.AssociationCategory;
import cn.edu.csust.coursecard.common.ReturnData;
import cn.edu.csust.coursecard.service.IAssociationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@RestController
public class AssociationController {
    
    @Autowired
    private IAssociationService associationService;
    
    @PostMapping("/category/add")
    @RequiredAdmin
    public ReturnData addAssociationCategory(@RequestBody AssociationCategory category){
        associationService.addCategory(category);
        return ReturnData.success();
    }
    
    
    @GetMapping("/category/getAll")
    public ReturnData getAllCategory(){
        List<AssociationCategory> categoryList = associationService.getAllCategory();
        return ReturnData.success(categoryList);
    }
    
    @GetMapping("/category/delete")
    @RequiredAdmin
    public ReturnData deleteCategory(@RequestParam("id")Integer categoryId){
        associationService.deleteCategory(categoryId);
        return ReturnData.success();
    }
    
    @PostMapping("/association/add")
    @RequiredAdmin
    public ReturnData addAssociation(Association association, MultipartFile file){
        associationService.addAssociation(association,file);
        return ReturnData.success();
    }
    
    @GetMapping("/association/delete")
    @RequiredAdmin
    public ReturnData deleteAssociation(@RequestParam("id")Integer associationId){
        associationService.deleteAssociation(associationId);
        return ReturnData.success();
    }
    
    @GetMapping("/association/get")
    public ReturnData getAssociationByCategory(@RequestParam("id") Integer categoryId){
        List<Association> associations = associationService.getAssociationByCategory(categoryId);
        return ReturnData.success(associations);
    }
    
    @GetMapping("/association/getAll")
    public ReturnData getAllAssociation(){
         List<Association> associations = associationService.getAllAssociation();
         return ReturnData.success(associations);
    }
}
